package com.html5;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.html5.utils.Constant;
import com.html5.utils.Utils;

@SuppressWarnings("serial")
public class Html5_showServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{
		String action =getMethod(request);
		if("language".equals(action)){
			setlocallanguage(request);
			return;
		}
		getServletContext().getNamedDispatcher(action).forward(request, response);
	}
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
	    throws ServletException, IOException{
		  if (request.getParameter("action") != null)
		      	doPost(request, response);
		  else
		      	getServletContext().getNamedDispatcher("default").forward(request, response);
	  }
	
	public String getMethod(HttpServletRequest request){
		String url[]=request.getRequestURI().split("/");
		return url[url.length-1];
	}
	
	public void setlocallanguage(HttpServletRequest request){
		String body=Utils.getBody(request);
		Constant.language=body;
	}
}
